package com.baidu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.baidu.constant.MessageConstant;
import com.baidu.entity.PageResult;
import com.baidu.entity.QueryPageBean;
import com.baidu.entity.Result;
import com.baidu.pojo.Sports;
import com.baidu.service.SportsService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sport")
public class SportsController {
    @Reference
    private SportsService sportsService;
    
    @RequestMapping("/findByPage")
    public PageResult findByPage(@RequestBody QueryPageBean queryPageBean){
        return sportsService.findByPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize(),queryPageBean.getQueryString());
    }

    @RequestMapping("/findSportsById")
    public Result findSportsById(Integer id){
        try{
            Sports sports=sportsService.findSportsById(id);
            return new Result(true,null,sports);
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false,"查询信息失败");
        }
    }

    @RequestMapping("/addSports")
    public Result addSports(@RequestBody Sports Sports){
        try{
            sportsService.addSports(Sports);
            return new Result(true, "添加成功");
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false,"添加失败");
        }
    }

    @RequestMapping("/editSports")
    public Result editSports(@RequestBody Sports sports){
        try{
            sportsService.editSports(sports);
            return new Result(true, "修改成功");
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false,"修改失败");
        }
    }

    @RequestMapping("/deleteSports")
    public Result editSports(Integer id){
        try{
            sportsService.deleteSportsById(id);
            return new Result(true, "删除成功");
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false,"删除失败");
        }
    }
}
